<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
	<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
    <script src="js/mui.min.js"></script>
	<script src="js/app.js"></script>
    <link href="css/mui.min.css" rel="stylesheet"/>

</head>
<body>
	<header class="mui-bar mui-bar-nav">
		<h1 class="mui-title">注册</h1>
	</header>
	<div class="mui-content" style="margin-top: 200px;">
		<form id='login-form' class="mui-input-group">
			<div class="mui-input-row">
				<label>账号</label>
				<input id='account' type="text" class="mui-input-clear mui-input" placeholder="请输入账号">
			</div>
			<div class="mui-input-row">
				<label>密码</label>
				<input id='password' type="password" class="mui-input-clear mui-input" placeholder="请输入密码">
			</div>
			<div class="mui-input-row">
				<label>验证码</label>
				<input id='imgCode' type="text" class="mui-input-clear mui-input"  placeholder="点击下方获取验证码">
			</div> 
			<div class="mui-input-row" id="gimg" style="text-align: center;background-color: rgb(232, 240, 254);">
				
				<div style="margin-top: 10px;" id="dianji">点击此处：</div><img src=""  id="getImgCode" style="height: 37px;margin-top: -8px;">
			</div> 
		</form>
		
		<div class="mui-content-padded">
			<button id='reg' class="mui-btn mui-btn-block mui-btn-primary">注册账号</button>
			<!-- <div class="link-area"><a id='login'>登录</a> <span class="spliter">
			</div> -->
			<div class="link-area"><a href="login1.html">登录地址</a> <span class="spliter">
			</div>
		</div>

	</div>
	
	
	<script type="text/javascript" charset="utf-8">
	  (function($, doc) {
		  
		 	
		  $.init({
	  		statusBarBackground: '#f7f7f7',
			
	  	});
		//检查 "登录状态/锁屏状态" 结束
		var loginButton = doc.getElementById('login');
		var accountBox = doc.getElementById('account');
		var passwordBox = doc.getElementById('password');
		var regButton = doc.getElementById('reg');
		var forgetButton = doc.getElementById('forgetPassword');
		var imgCode = doc.getElementById('imgCode');
		var getImgCode = doc.getElementById('getImgCode');
		var gimgButton = doc.getElementById('gimg');
		
		gimgButton.addEventListener('tap', function(event) {
			console.log("sds");
			var mobile=accountBox.value;
			    	if(mobile==""){
			    		 $.toast("请输入账号");
			    		return;
			    	} 
					doc.getElementById("dianji").textContent='';
			    	doc.getElementById("getImgCode").src=api+"/other/getImgCode?telephone="+mobile+"&time="+new Date()/1000;
					console.log("http://localhost:9888/other/getImgCode?telephone="+mobile+"&time="+new Date()/1000)
		});
		regButton.addEventListener('tap', function(event) {
			var pid=getQueryVariable("pid");
			pid=pid==false?1000:pid
			console.log(pid);
			console.log(accountBox.value);
			if(!accountBox.value||accountBox.value.length<4){
				$.toast("请输入帐号，必须大于3位")
				return ;
			}
			if(!passwordBox.value||passwordBox.value.length<6){
				$.toast("请输入密码,密码必须大于等于6位数")
				return ;
			}
			if(!imgCode.value){
				$.toast("请输入验证码")
				return ;
			}
			$.ajax(api+'/user/register',{
				data:{
					mobile:accountBox.value,
					password:passwordBox.value,
					pid:pid,
					imgCode:imgCode.value
				},
				dataType:'json',//服务器返回json格式数据
				crossDomain:true,
				type:'post',//HTTP请求类型
				timeout:10000,//超时时间设置为10秒；data
				headers:{'Content-Type':'application/json'},	              
				success:function(data){
					if(data.code==1){
						$.toast("注册成功")
						// localStorage.setItem("userinfo",JSON.stringify(data.data))
						// setTimeout(function () {
						// 	plus.webview.hide('reg.html');
						// 	plus.webview.show("index.html");
						// },20);
						location.href="login1.html";
					}else{
						$.toast(data.msg)
					}
					
				},
				error:function(xhr,type,errorThrown){
					alert(type)
					//异常处理；
					console.log(type);
				}
			});
		});
		loginButton.addEventListener('tap',function(){
			location.href='login1.html';
		});
		function getQueryVariable(variable)
		{
		       var query = window.location.search.substring(1);
		       var vars = query.split("&");
		       for (var i=0;i<vars.length;i++) {
		               var pair = vars[i].split("=");
		               if(pair[0] == variable){return pair[1];}
		       }
		       return(false);
		}
	  }(mui, document));
	</script>
</body>
</html>